<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>仓库信息管理</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/jsp/yd/logic/ItemStateData.js"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/yd/logic/poreturn";
		var ItemStateList = ItemStateData.Rows;
		var bd = '${itemBatchDOs}';
		//var delBd = '${delItemBatchDOs}';
 		//alert("bd:"+bd);
// 		function createSearch(){
// 			init(1,6,'100,100,100,100,100,100','10%');
// 			//第一行的数据
// 			addCommon(0,0,"lable","物料编码：");
// 			addCommon(0,1,"txtlike","code");
// 			addCommon(0,2,"lable","物料名称：");
// 			addCommon(0,3,"txtlike","name");
// 			addCommon(0,4,"lable","规格型号：");
// 			addCommon(0,5,"txtlike","spec");
// 		}
		
// 		function searchAP(){
// 			multipleSearch("#table1",true,"",basic_Url+"/itemlist.do?componentSequenceId="+componentSequenceId);
// 		}
		var grid;
		$(function(){
			var column1 =  [
					  { display: 'id', name: 'id', width: 1 ,hide:true},
					  { display: 'materialsid', name: 'materialsid', width: 1,hide:true },
					  { display: '<font color="gray">物料编码</font>', name: 'code', width: 1,width: 150 },
	                  { display: '<font color="gray">物料名称</font>', name: 'name', width: 150 },
	                  { display: '<font color="gray">单位</font>', name: 'unit', width: 120},
	                  { display: '<font color="gray">订单数量</font>', name: 'quantity', width: 120},
	                  { display: '<font color="gray">基本单位</font>', name: 'junit', width: 120},
	                  { display: '<font color="gray">基本单位订单数量</font>', name: 'jquantity', width: 120},
	                  { display: '<font color="gray">型号规格</font>', name: 'spec', width: 245},
	                  { display: '<font color="gray">批次</font>', name: 'batch', width: 120},
	                  { display: '<font color="gray">物料状态</font>', name: 'state', width: 120,
	                	  render: function (item){
	                		  var state=item.state;
	                		  if(state=="1"){
	                			  return "一等";
	                		  }
	                		  if(state=="2"){
	                			  return "次货";
	                		  }
	                		  if(state=="3"){
	                			  return "旧件";
	                		  }
	                	  }},
	                  { display: '<font color="gray">(基本单位)入库数量</font>', name: 'jhealthycount', width: 120},
	                  { display: '<font color="gray">入库数量</font>', name: 'healthycount', width: 120},
	                  { display: '<font color="gray">基本单位已退货数量</font>', name: 'jbadcount', width: 120},
	                  { display: '<font color="gray">已退货数量</font>', name: 'badcount', width: 120},
	                  { display: '<font color="gray">基本单位退货数量</font>', name: 'jreturnquantity', width: 120},
	                  { display: '退货数量<font color="red">*</font>', name: 'returnquantity', width: 120,editor: { type: 'float'},render:function(item){
	                	  if(item.returnquantity!=''&&item.returnquantity!=null&&item.unitconvert!=null&&item.unitconvert!=''){
	                		  grid.updateCell('jreturnquantity', (item.returnquantity*(item.unitconvert)).toFixed(4), item);
	            	   		}
	                	  return  (item.returnquantity==undefined ? 0:parseFloat(item.returnquantity).toFixed(4));
	                       	
	           }},
	           { display: '<font color="gray">单位换算率</font>', name: 'unitconvert', width: 120}
			                  ];
			var column2 =  [
						{ display: 'id', name: 'id', width: 1 ,hide:true},
						{ display: 'materialsid', name: 'materialsid', width: 1,hide:true },
						{ display: '<font color="gray">物料编码</font>', name: 'code', width: 1,width: 150 },
						{ display: '<font color="gray">物料名称</font>', name: 'name', width: 150 },
						{ display: '<font color="gray">单位</font>', name: 'unit', width: 120},
						{ display: '<font color="gray">订单数量</font>', name: 'quantity', width: 120},
						{ display: '<font color="gray">基本单位</font>', name: 'junit', width: 120},
						{ display: '<font color="gray">基本单位订单数量</font>', name: 'jquantity', width: 120},
						{ display: '<font color="gray">型号规格</font>', name: 'spec', width: 245},
						{ display: '<font color="gray">批次</font>', name: 'batch', width: 120},
						{ display: '<font color="gray">物料状态</font>', name: 'state', width: 120,
							  render: function (item){
								  var state=item.state;
								  if(state=="1"){
									  return "一等";
								  }
								  if(state=="2"){
									  return "次货";
								  }
								  if(state=="3"){
									  return "旧件";
								  }
							  }},
						{ display: '<font color="gray">(基本单位)入库总数量</font>', name: 'jhealthycount', width: 120},
						{ display: '<font color="gray">入库总数量</font>', name: 'healthycount', width: 120},
						{ display: '<font color="gray">基本单位已退货数量</font>', name: 'jbadcount', width: 120},
						{ display: '<font color="gray">已退货数量</font>', name: 'badcount', width: 120},
						{ display: '<font color="gray">基本单位退货数量</font>', name: 'jreturnquantity', width: 120},
						{ display: '退货数量<font color="red">*</font>', name: 'returnquantity', width: 120},
						{ display: '<font color="gray">单位换算率</font>', name: 'unitconvert', width: 120}
			                  ];
			//var colunm3 = column1;                 
// 		    if('${billstatus}' != "" && '${billstatus}' != "0"){
// 		    	colunm3 = column2;    
// 		    }
 if('${billstatus}' != "" && '${billstatus}' != "0"){
	 grid = $("#table1").ligerGrid({
	        columns: column2, 
	                      enabledEdit: true,
	                      usePager: true,pageSize:1000,pageSizeOptions:[1000],enabledSort:false, checkbox: true,
	                      url : basic_Url+"/itemlist.do?itembatch="+encodeURIComponent(bd)+"&updstatus="+"${updstatus}",
	                      width: "100%", height:"98%"
	                  });
 }else{
	 grid = $("#table1").ligerGrid({
	        columns: column1, 
	                      enabledEdit: true,
	                      usePager: true,pageSize:1000,pageSizeOptions:[1000],enabledSort:false, checkbox: true,
	                      url : basic_Url+"/itemlist.do?itembatch="+encodeURIComponent(bd)+"&updstatus="+"${updstatus}",
	                      width: "100%", height:"98%",
	                      toolbar: { items: [
	                                         { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
	                                         ]
	                                         }
	                  });
 }
				
				wareitemid ='';
				code ='';
			$("#pageloading").hide();
		
		
		});
		function deleteRow()
		{ if('${billstatus}' != "" && '${billstatus}' != "0"){
			return false;
		}else{
			grid.deleteSelectedRow();
		}
		}
		function getSelected(){
			var rows = grid.getCheckedRows();
			 return rows;
		}
		
		function Close(){
			CloseDialog();
		}
		var ba=true;
		var num = 0;
		var jnum = 0;
		function yz(){
			var data = grid.getData();
			if (data != null && data.length > 0) {
				jnum = 0;
				num = 0;
				for ( var i = 0; i < data.length; i++) {
					if(data[i].jbadcount == null || data[i].jbadcount.length<=0){
						data[i].jbadcount = 0;
					}
					if((parseFloat(data[i].jreturnquantity)+parseFloat(data[i].jbadcount))>parseFloat(data[i].jhealthycount)){
						$.dialog.alert("您第" + (i+1) + "的退货数量大于单据的入库数量");
						ba = false;
						return false;
					}
					if(data[i].returnquantity<=0){
						$.dialog.alert("您第" + (i+1) + "行的退货数量不能小于等于0");
						ba = false;
						return false;
					}
					if (isNaN(data[i].returnquantity) ||data[i].returnquantity==undefined ||data[i].returnquantity==null) {
						ba = false;
						$.dialog.alert("您第" + (i+1) + "行的退货数量没有填写");
						return false;
					}
					jnum +=parseFloat(data[i].jreturnquantity);
					num +=parseFloat(data[i].returnquantity);
	 			}
			}
				ba=true;
		}
	</script>
	
  </head>
 <body style="padding:10px">  
       <div id="layout1">
       <div id="layout1">
          <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
               </div>
          </div>
      </div>
      <div position="center" id="table1">
      </div>
      <div class="clear"></div>
   </div>
    </body>
</html>